//设备打印
OB.EMES_FACILITIES_PRINT= function(params, view) {
    var viewGrid = view.activeView.viewGrid;
    var records = viewGrid.getSelectedRecords();
    var codes = [];
    var names = [];
    var vendor_Names = [];
    var ori_Numbers = [];
    var fancilityType = {};
    var type = {};
    for(var i=0;i<records.length;i++){
    	fancilityType[records[i].fancilityType] = records[i].fancilityType;
        type[records[i].type] = records[i].type;
    }
    var keys = [];
    var typeKeys = [];
    for(var key in fancilityType){
    	keys.push(key);
    }
    for(var key in type){
        typeKeys.push(key);
    }
    for(var i=0;i<records.length;i++){
        codes.push(records[i].code);
        names.push(records[i].name);
        vendor_Names.push(records[i].vendorName);
        ori_Numbers.push(records[i].oriNumber);
    }
    if(typeKeys.length == 1 && typeKeys[0] == 'MANUFACTURE'){
        sbShow(codes,names,vendor_Names,ori_Numbers);//设备打印
    }else{
        if(keys.length > 1){
            isc.showMessage("只能选择一种设备类别的设备进行打印！");
            return ;
        }else if(keys.length == 0){
            isc.showMessage("请选择设备类别不为空的设备进行打印！");
            return ;
        }
        if(keys.length==1){
            if(keys[0] == 'HL'){//花篮
                hlShow(codes,names);
            }else if(keys[0] == 'SMZ'){//石墨舟
                smzBarcode(codes,names);
            }else if(keys[0] == 'SMK'){//石墨框
                smkBarcode(codes,names);
            }
        }
    }
}

function hlShow(codes,names) {
	var LODOP = getCLodopA();
	LODOP.PRINT_INIT("");
    for (var i = 1; i <= codes.length; i=i+2) {
        var k= i >25 ? (i%26) : i;
        if(i%26==1){
          LODOP.NEWPAGE();
        }
        LODOP.ADD_PRINT_TEXT(11+(k/2*75), 38, 120, 22, names[i-1]);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_BARCODE(33+(k/2*75), 29, 137, 34, "128A", codes[i-1]);
        LODOP.ADD_PRINT_RECT(4+(k/2*75), 11, 165, 68, 0, 1);
        
        LODOP.ADD_PRINT_TEXT(11+(k/2*75), 38+(180*1), 120, 22, names[i-1]);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_BARCODE(33+(k/2*75), 29+(180*1), 137, 34, "128A", codes[i-1]);
        LODOP.ADD_PRINT_RECT(4+(k/2*75), 11+(180*1), 165, 68, 0, 1);
        if(i+1<=codes.length){
          LODOP.ADD_PRINT_TEXT(11+(k/2*75), 38+(180*2), 120, 22, names[i]);
          LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
          LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
          LODOP.ADD_PRINT_BARCODE(33+(k/2*75), 29+(180*2), 137, 34, "128A", codes[i]);
          LODOP.ADD_PRINT_RECT(4+(k/2*75), 11+(180*2), 165, 68, 0, 1);
          
          LODOP.ADD_PRINT_TEXT(11+(k/2*75), 38+(180*3), 120, 22, names[i]);
          LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
          LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
          LODOP.ADD_PRINT_BARCODE(33+(k/2*75), 29+(180*3), 137, 34, "128A", codes[i]);
          LODOP.ADD_PRINT_RECT(4+(k/2*75), 11+(180*3), 165, 68, 0, 1);
        }
    }
    LODOP.PREVIEW();
}

function smzBarcode(codes,names) {
	var LODOP = getCLodopA();
    LODOP.PRINT_INIT("");
    for (var i = 1; i <= codes.length; i=i+2) {
        var k= i >23 ? (i%24) : i;
        if(i%24==1){
          LODOP.NEWPAGE();
        }
        LODOP.ADD_PRINT_TEXT(11+(k/2*85), 28, 140, 22, names[i-1]);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_BARCODE(33+(k/2*85), 29, 137, 34, "Code39", codes[i-1]);
        LODOP.ADD_PRINT_RECT(4+(k/2*85), 11, 165, 68, 0, 1);
        
        //LODOP.ADD_PRINT_TEXT(11+(k/2*75), 28+(180*1), 140, 22, names[i-1]);
        //LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
        //LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        //LODOP.ADD_PRINT_BARCODE(33+(k/2*75), 29+(180*1), 137, 34, "128A", codes[i-1]);
        //LODOP.ADD_PRINT_RECT(4+(k/2*75), 11+(180*1), 165, 68, 0, 1);
        if(i+1<=codes.length){
          //LODOP.ADD_PRINT_TEXT(11+(k/2*75), 28+(180*2), 140, 22, names[i]);
          //LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
          //LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
          //LODOP.ADD_PRINT_BARCODE(33+(k/2*75), 29+(180*2), 137, 34, "128A", codes[i]);
          //LODOP.ADD_PRINT_RECT(4+(k/2*75), 11+(180*2), 165, 68, 0, 1);
          
          LODOP.ADD_PRINT_TEXT(11+(k/2*85), 28+(180*3), 140, 22, names[i]);
          LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
          LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
          LODOP.ADD_PRINT_BARCODE(33+(k/2*85), 29+(180*3), 137, 34, "Code39", codes[i]);
          LODOP.ADD_PRINT_RECT(4+(k/2*85), 11+(180*3), 165, 68, 0, 1);
        }
    }
    LODOP.PREVIEW();
}

function smkBarcode(codes,names) {
	var LODOP = getCLodopA();
    LODOP.PRINT_INIT("");
    for (var i = 1; i <= codes.length; i=i+2) {
        var k= i >23 ? (i%24) : i;
        if(i%24==1){
          LODOP.NEWPAGE();
        }
        LODOP.ADD_PRINT_TEXT(11+(k/2*85), 28, 140, 22, names[i-1]);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_BARCODE(33+(k/2*85), 29, 137, 34, "128A", codes[i-1]);
        LODOP.ADD_PRINT_RECT(4+(k/2*85), 11, 165, 68, 0, 1);
        
        //LODOP.ADD_PRINT_TEXT(11+(k/2*75), 28+(180*1), 140, 22, names[i-1]);
        //LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
        //LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        //LODOP.ADD_PRINT_BARCODE(33+(k/2*75), 29+(180*1), 137, 34, "128A", codes[i-1]);
        //LODOP.ADD_PRINT_RECT(4+(k/2*75), 11+(180*1), 165, 68, 0, 1);
        if(i+1<=codes.length){
          //LODOP.ADD_PRINT_TEXT(11+(k/2*75), 28+(180*2), 140, 22, names[i]);
          //LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
          //LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
          //LODOP.ADD_PRINT_BARCODE(33+(k/2*75), 29+(180*2), 137, 34, "128A", codes[i]);
          //LODOP.ADD_PRINT_RECT(4+(k/2*75), 11+(180*2), 165, 68, 0, 1);
          
          LODOP.ADD_PRINT_TEXT(11+(k/2*85), 28+(180*3), 140, 22, names[i]);
          LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
          LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
          LODOP.ADD_PRINT_BARCODE(33+(k/2*85), 29+(180*3), 137, 34, "128A", codes[i]);
          LODOP.ADD_PRINT_RECT(4+(k/2*85), 11+(180*3), 165, 68, 0, 1);
        }
    }
    LODOP.PREVIEW();
}

function sbShow(codes,names,vendor_Names,ori_Numbers){
    var LODOP = getCLodopA();
    LODOP.PRINT_INIT("");
    for (var i = 0; i < codes.length; i++) {
        LODOP.ADD_PRINT_BARCODE(191, 152, 227, 44, "128A", codes[i]);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 7);
        LODOP.ADD_PRINT_TEXT(44, 33, 120, 28, "设备名称：");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 14);
        LODOP.ADD_PRINT_TEXT(44, 151, 222, 28, names[i]);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 14);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_TEXT(78, 32, 120, 28, "规格型号：");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 14);
        LODOP.ADD_PRINT_TEXT(80, 153, 222, 28, ori_Numbers[i]);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 14);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_TEXT(154, 30, 120, 28, "责 任 人：");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 14);
        LODOP.ADD_PRINT_TEXT(119, 151, 222, 28, vendor_Names[i]);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 14);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.ADD_PRINT_TEXT(118, 30, 120, 28, "供 应 商：");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 14);
        LODOP.ADD_PRINT_RECT(35, 24, 380, 212, 0, 1);
        LODOP.NEWPAGE();
    }
    LODOP.PREVIEW();
}